#!/usr/bin/env python

import unittest
from rawdb import RawDB
from db import DB, VersionedDB
from bank import Bank, VersionedBank

class Bank_Test( unittest.TestCase ):
    def setUp( self ):
        self.bank = Bank( DB( RawDB() ) )
    # setUp()


    def testCase1( self ):
        self.bank.deposit( 1, 1000 )
        self.assertEqual( self.bank.consult( 1 ), 1000 )

        self.bank.withdraw( 1, 600 )
        self.assertEqual( self.bank.consult( 1 ), 400 )
    # testCase1()


    def testMultipleConsult( self ):
        self.bank.deposit( 1, 1000 )
        self.bank.deposit( 2, 2000 )
        self.bank.deposit( 3, 3000 )
        result = self.bank.multipleConsult( [ 1, 2, 3 ] )
        self.assertEqual( result, [ 1000, 2000, 3000 ] )
    # testMultipleConsult()


    def testDepositWithdraw2Accounts( self ):
        self.bank.deposit( 4, 4444 )
        self.bank.deposit( 5, 55555 )
        self.bank.withdraw( 4, 4445 )
        self.bank.withdraw( 5, 55554 )

        self.assertEqual( self.bank.consult( 4 ), -1 )
        self.assertEqual( self.bank.consult( 5 ), 1 )
    # testDepositWithdraw2Accounts()


    def testDepositsSameAccount( self ):
        self.bank.deposit( 6, 600 )
        self.assertEqual( self.bank.consult( 6 ), 600 )

        self.bank.deposit( 6, 700 )
        self.assertEqual( self.bank.consult( 6 ), 1300 )

        self.bank.deposit( 6, 800 )
        self.assertEqual( self.bank.consult( 6 ), 2100 )
    # testDepositsSameAccount()

    def testWithdrawNewAccount( self ):
        self.bank.withdraw( 7, 100 )
        self.assertEqual( self.bank.consult( 7 ), -100 )
    # testWithdrawNewAccount()


    def testTransfer( self ):
        self.bank.deposit( 12, 1000)
        self.bank.transfer( 12, 13, 100)
        self.assertEqual( self.bank.consult( 12 ), 900)
        self.assertEqual( self.bank.consult( 13 ), 100)
    # testTransfer()


    def testTransferNeg( self ):
        self.bank.deposit( 14, 1000)
        self.bank.transfer( 14, 15, 2000)
        self.assertEqual( self.bank.consult( 14 ), -1000)
        self.assertEqual( self.bank.consult( 15 ), 2000)
    # testTransferNeg()
# Bank_Test


class VersionedBank_Test( unittest.TestCase ):
    def setUp( self ):
        self.vbank = VersionedBank( VersionedDB( RawDB(), [] ) )
    # setUp()


    def testCase1( self ):
        self.vbank.deposit( 1, 1000 )
        self.assertEqual( self.vbank.consult( 1 ), 1000 )

        self.vbank.withdraw( 1, 600 )
        self.assertEqual( self.vbank.consult( 1 ), 400 )
    # testCase1()
# VersionedBank_Test



if __name__ == "__main__":
    unittest.main()
# endif
